package com.wwwarehouse.resource_center.fragment.sales_Inventory_statistics;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.adapter.salesInventory_statistics.SalesInventoryStatisticsAdapter;
import com.wwwarehouse.resource_center.bean.sales_inventory_statistics.SalesInventoryStatisticsResponseBean;

import java.util.ArrayList;

/**
 * Created by Jackie 2017/10/26
 * 销售库存信息统计
 */
public class SalesInventoryStatisticsDetailsFragment extends BaseFragment {
    private View mRootView;

    private RecyclerView recyclerView;

    private ArrayList<SalesInventoryStatisticsResponseBean.ListBean> dataList;
    private SalesInventoryStatisticsAdapter adapter;
    private int page;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_sales_inventory_statistics_details, container, false);
        return mRootView;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof SalesInventoryStatisticsDetailsFragment)
            mActivity.setTitle(R.string.sales_inventory_statistics);
    }

    @Override
    public void requestDatas() {
        recyclerView = (RecyclerView) mRootView.findViewById(R.id.recycler_view);

        dataList = getArguments().getParcelableArrayList("dataList");
        page = getArguments().getInt("page");

        int count = page * SalesInventoryStatisticsListFragment.SIZE;
        if (count > dataList.size())
            count = dataList.size();
        ArrayList<SalesInventoryStatisticsResponseBean.ListBean> list = new ArrayList<>();
        for (int i = (page - 1) * SalesInventoryStatisticsListFragment.SIZE; i < count; i++) {
            list.add(dataList.get(i));
        }
        adapter = new SalesInventoryStatisticsAdapter(mActivity, list, recyclerView.getMeasuredHeight());
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(adapter);
    }
}
